package com.k2091.washcar.controller;


import com.k2091.washcar.entity.Cleaner;
import com.k2091.washcar.entity.Examine;
import com.k2091.washcar.entity.FormInline;
import com.k2091.washcar.entity.Users;
import com.k2091.washcar.service.ICleanerService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-06-01
 */
@Controller
@RequestMapping("/api/cleaner")
public class CleanerController {
    @Autowired
    private ICleanerService cleanerService;

    /**
     * 我要成为洗车员
     * @param examine
     * @return
     */
    @RequestMapping("/addCleaner")
    @ResponseBody
    public int addCleaner(@RequestBody Examine examine) {
        int r = cleanerService.insert(examine);
        return r;
    }


    //后台管理
    @RequestMapping("/upCleaner")
    @ResponseBody
    public int upCleaner(Cleaner cleaner){
        int r = 0;
        if (cleanerService.selectById(cleaner.getId())!=null){
            r = cleanerService.upCleaner(cleaner);
        }else {
            r = cleanerService.createrCleaner(cleaner);
        }
        return r;
    }

    @RequestMapping("/getCleanerList")
    @ResponseBody
    public List<Cleaner> selectCleaner(FormInline formInline){
        return cleanerService.selectCleaner(formInline);
    }

    @RequestMapping("/upCleanerStatus")
    @ResponseBody
    public void upCleanerStatus(@Param("id")Long id, @Param("status")int status, @Param("token")String token){
        cleanerService.upCleanerStatus(id, status, token);
    }

    @RequestMapping("/deleteCleaner")
    @ResponseBody
    public void deleteCleaner(Long id){
        cleanerService.deleteCleaner(id);
    }


    public void cleanerMoney(Long id){

    }
}


